package com.atguigu.gmall.mq.receiver;


import com.atguigu.gmall.mq.config.DelayMqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class DelayMessage {

    @RabbitListener(queues = DelayMqConfig.queue_delay_1)
    public void message(String msg, Message message, Channel channel){
        try {
            System.out.println("接收到的消息：" + msg);
            System.out.println("接收到的消息时间：" + new Date());
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
